<?php

class baseController extends Controller{
	
	function __construct() {
		if(!UserPrivHelper::checkurl()){
			Show::warn('无权操作');
		}
		/*
		 * 防刷新(重复提交)验证
		 */
		if(is_post()){
			$delay = 3;
			$key = md5(serialize($_POST));
			if(!empty($_SESSION['ANTIFRUSH'])){
				if( ($_SESSION['ANTIFRUSH'][0] +$delay > time())
						&& ($_SESSION['ANTIFRUSH'][1]==$key) ){
					Show::warn( '相同数据'. 
							(time() - $_SESSION['ANTIFRUSH'][0])
							.'秒之前已处理，请勿重复提交' );
				}
			}
			$_SESSION['ANTIFRUSH'] = array(time(), $key);
		}
		elseif(!is_ajax()){
                   	//$this->assign('reminders', ReviewerHelper::getReminders());
                    //    $this->assign('feedbacks', ReviewerHelper::getFeedback());
		}
	}
	
	function display($_act = null, $_layout = null) {
        $this->assign('GUSER', UserAuthHelper::getUser());
        $this->assign('ROLES', RoleHelper::getByUser(UID));
        $this->assign('ptree', UserPrivHelper::privTree());

		if(!$_act){
			$_act = $_REQUEST['a'];
		}
//		echo $_act;
		if(isset($_GET['viewtype'])){
			switch($_GET['viewtype']){
			case 'print':
				$this->assign('printview', true);
				parent::display($_act.'~print', $_layout);
				break;
			case 'csv':
				$this->assign('printview', true);
				parent::display($_act.'~csv', $_layout);
				break;
			}
		}
		else{
			if(false!==strpos(app_cfg('setting', 'view-print'),"|{$_act}|")){
				$this->assign('printable', true);
			}
			if(false!==strpos(app_cfg('setting', 'view-csv'),"|{$_act}|")){
				$this->assign('csvable', true);
			}
			parent::display($_act, $_layout);
		}
	}
	
}

?>
